<?php
 include_once('config/config.php');
 // 获取id
 if(!$_GET){
	ShowMsg('请选择编辑的数据','joblist.php');
	exit;
 }
 // 
 $id = $_GET['id'];
 // 
 $sql = 'SELECT j.id, j.name, d.name AS department FROM pre_job AS j LEFT JOIN pre_department AS d ON j.depid = d.id WHERE j.id = '.$id.';';
 
 $result = departmentid($sql);
 
 $job_name = $result['0']['1'];
 $pre_name = $result['0']['2'];
 // exit;
 // 查询有几个部门
 $sql = "SELECT * FROM pre_department;";
 
 $arr_prename = all($sql);
 
 // 提交修改的数据
 if($_POST){
	 // 职位名称
	$subjob_name = $_POST['job_name'];
	// 部门id
	$subpre_id = $_POST['pre_id'];
	// 部门名称
	$subpre_name = filter($subpre_id);
	$sql = "UPDATE `pre_job` SET `name`='$subjob_name' , `depid` = $subpre_id WHERE id = $id;";
	// 
	$res = departmentup($sql);
	if($res){
		ShowMsg('修改成功！','joblist.php');
	}
 }
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<?php include_once('common/meta.php'); ?>
	</head>
	<style>
		
	</style>
	<body>
		<!--<![endif]-->

		<?php include_once('common/header.php'); ?>

		<?php include_once('common/sidebar.php'); ?>

		<div class="content">
			<div class="header">
				<h1 class="page-title">修改职位</h1>
			</div>
			<ul class="breadcrumb">
				<li><a href="index.php">Home</a> <span class="divider">/</span></li>
				<li class="active">Index</li>
			</ul>

			<div class="container-fluid">
				<div class="row-fluid">

					<div class="btn-toolbar">
						<button class="btn btn-primary" onClick="location='joblist.php'"><i class="icon-list"></i>职位列表</button>
						<div class="btn-group">
						</div>
					</div>
					
					<div class="well">
						<div id="myTabContent" class="tab-content">
							<div class="tab-pane active in" id="home">
								<form method="post" enctype="multipart/form-data">
									<!-- 职位名称 -->
									<label>职位名称</label>
									<input type="text" name="job_name" class="input-xxlarge" value="<?php echo $job_name ?>" placeholder="请输入职位名称" required />
									<!-- 部门 -->
									<label>部门</label>
									<select name="pre_id">
										<?php foreach($arr_prename as $prename){ ?>
										<option <?php echo $prename['name'] ==  $pre_name ? 'selected' : ' ' ?> value="<?php echo $prename['id'] ?>"><?php echo $prename['name'] ?></option>
										<?php } ?>
									</select>
									
									<br />
									<!-- 提交 -->
									<button type="submit" class="btn btn-primary">提交</button>
								</form>
							</div>
						</div>
					</div>
					<?php include_once('common/footer.php'); ?>

				</div>
			</div>
		</div>

		<?php include_once('common/script.php'); ?>

	</body>
</html>
